package com.huazi.commonutils;

import lombok.Data;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author shkstart
 * @create 2021-03-17 10:06
 */
@Data
public class PropertyInfo {//国际化信息类
    private String login;
    private String title;
    private String username;
    private String password;
    private String chinese;
    private String english;

    private PropertyInfo(){}
    private static PropertyInfo propertyInfo=new PropertyInfo();
    public static PropertyInfo getInstance(String login,String title,String username,String password,String chinese,String english){
        propertyInfo.login=login;
        propertyInfo.title=title;
        propertyInfo.username=username;
        propertyInfo.password=password;
        propertyInfo.chinese=chinese;
        propertyInfo.english=english;
        return propertyInfo;
    }
    public static PropertyInfo getLocal(String local){
        String path="/zh.properties";
        if("us".equals(local)) path="/us.properties";
        Properties prop=new Properties();
        System.out.println("进入prop");
        InputStream is=PropertyInfo.class.getResourceAsStream(path);
        try {
            prop.load(is);
            String login = prop.getProperty("login");
            String title = prop.getProperty("title");
            String username = prop.getProperty("username");
            String password = prop.getProperty("password");
            String chinese = prop.getProperty("chinese");
            String english = prop.getProperty("english");
            return getInstance(login,title,username,password,chinese,english);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return propertyInfo;
    }

}
